<template>
    <div class="w-full h-full">
        <div class="text-h5">
            评论审核
        </div>
        <div v-if="blogs">
        </div>
        <q-table v-if="blogs.length > 0" :rows="blogs" :columns="columns">
            <template v-slot:body="props">
                <q-tr :props="props">
                    <q-td :props="props" key="comment">
                        <span v-html="props.row.comment"></span>
                    </q-td>
                    <q-td :props="props" key="user_id">
                        {{ props.row.user_id }}
                    </q-td>
                    <q-td :props="props" key="username">
                        {{ props.row.username }}
                    </q-td>
                    <q-td :props="props" key="vis">
                        {{ props.row.vis === 0 ? '未审核' : '已审核' }}
                    </q-td>
                    <q-td :props="props" key="id">
                        {{ props.row.id }}
                    </q-td>
                    <q-td :props="props" key="id">
                        <q-btn type="primary" label="审核" @click="updateStatus(props.row)" />
                        <q-btn color="red-10" label="删除" @click="deleteOne(props.row)" />
                    </q-td>
                </q-tr>

            </template>
        </q-table>
    </div>
</template>
<script setup>
import { ref } from 'vue'
import { api } from 'src/boot/axios';
import { getAllBlogs } from 'src/boot/blogs/blogs';
import { getOne } from 'src/boot/coments';
import { useQuasar } from 'quasar'
const $q = useQuasar()
const blogs = ref([])
const columns = [

    { name: 'comment', label: 'comment', field: 'comment' },
    { name: 'user_id', label: 'user_id', field: 'user_id' },
    { name: 'username', label: 'username', field: 'username' },
    { name: 'vis', label: '状态', field: 'vis', sortable: true },
    { name: 'id', label: 'id', field: 'id' },
    {
        name: '操作', label: '操作', field: 'id', align: 'center'
    }
]

getOne({}).then(res => {
    blogs.value = res.data.data
})


function updateStatus(item) {
    api.post('/comments/update_one', { "cond": { id: item.id }, "item": { vis: 1 } }).then(res => {
        if (res.data.code === 200) {
            $q.notify({
                color: 'positive',
                position: 'top',
                message: '审核成功',
                icon: 'check'
            })
        } else {
            $q.notify({
                color: 'negative',
                position: 'top',
                message: '审核失败',
                icon: 'close'
            })
        }
    })
}
function deleteOne(item) {
    api.post('/comments/delete_one', item).then(res => {
        if (res.data.code === 200) {
            $q.notify({
                color: 'positive',
                position: 'top',
                message: '删除成功',
                icon: 'check'
            })
        } else {
            $q.notify({
                color: 'negative',
                position: 'top',
                message: '删除失败',
                icon: 'close'
            })
        }
    })
}

</script>